package org.qphoto;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Message {
	public long getMessageid() {
		return messageid;
	}
	public void setMessageid(long messageid) {
		this.messageid = messageid;
	}
	public long getUserid() {
		return userid;
	}
	public void setUserid(long userid) {
		this.userid = userid;
	}
	public String getPosttime() {
		return posttime;
	}
	public String getShowPostTime()
	{
		StringBuilder sb = new StringBuilder();
		Date date = Message.getDateFromTimeString(posttime);
		Date now  = new Date();
		if ( now.getYear()  == date.getYear() &&
			 now.getMonth() == date.getMonth() &&
			 now.getDay() == date.getDay() )
		{
			if ( date.getHours() < 10)
				sb.append("0");
			sb.append(date.getHours());
			sb.append(":");
			if ( date.getMinutes() < 10)
				sb.append("0");
			sb.append(date.getMinutes());
		} else {
			if ( date.getMonth() < 10)
				sb.append("0");
			sb.append(date.getMonth());
			sb.append("-");
			if ( date.getDay() < 10)
				sb.append("0");
			sb.append(date.getDay());
		}
		return sb.toString();
	}
	public void setPosttime(String posttime) {
		this.posttime = posttime;
	}
	public boolean isBreply() {
		return breply;
	}
	public void setBreply(boolean breply) {
		this.breply = breply;
	}
	public long getRootmessageid() {
		return rootmessageid;
	}
	public void setRootmessageid(long rootmessageid) {
		this.rootmessageid = rootmessageid;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getImageuri() {
		return imageuri;
	}
	public void setImageuri(String imageuri) {
		this.imageuri = imageuri;
	}
	public String getAudiouri() {
		return audiouri;
	}
	public void setAudiouri(String audiouri) {
		this.audiouri = audiouri;
	}
	
	public Message()
	{
		messageid     = 0;
		rootmessageid = 0;
		content       = "";
		imageuri      = "";
		audiouri      = "";
		videouri      = "";
		breply        = false;
		userid        = 0;
		posttime      = getCurrentTimeString();
		username      = "";
		realname      = null;
		avatar        = "";
	}
	private long    messageid;
	private long    userid;
	private String  posttime;
	private boolean breply;
	private long    rootmessageid;
	private String  content;
	private String  imageuri;
	private String  audiouri;
	private String  videouri;
	
	public String getVideouri() {
		return videouri;
	}
	public void setVideouri(String videouri) {
		this.videouri = videouri;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getAvatar() {
		return avatar;
	}
	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}
	private String  username;
	private String  realname;
	public String getRealname() {
		return realname;
	}
	public void setRealname(String realname) {
		this.realname = realname;
	}
	private String  avatar;
	
	public static String getCurrentTimeString()
	{
		Date date = new Date();
        DateFormat dateFormat = 
            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(date);
	}
	
	public static Date getDateFromTimeString(String timestr)
	{
		Date d = null;
		DateFormat dateFormat = 
	            new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			d = dateFormat.parse(timestr);
			return d;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new Date();
	}
	
	public static long getTimeInterval(Date t1,Date t2)
	{
		return (long) Math.abs( t2.getTime() - t1.getTime() );
	}
	
	
}
